package com.copro.chemdb.result;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.apache.struts.action.ActionForm;

import com.copro.chemdb.subject.Subject;

public class Result extends ActionForm {

	private static final long serialVersionUID = -3609079954651667742L;

	public static final int FROM_QUEST = 0;
	public static final int FROM_DB = 1;

	public Result() {
		answers = new LinkedList<Answer>();
	}

	public Result(ResultSet rs) throws SQLException {
		this();
		this.id = rs.getInt("id");
		this.quesId = rs.getInt("id_T_questionnaire");
		this.parentId = rs.getInt("id_T_result");
		this.user = rs.getString("user");
		this.createTime = rs.getDate("createTime");
		try {
			this.brief = rs.getString("brief");
		} catch (Exception e) {
			this.brief = null;
		}
		this.type = rs.getInt("type");
	}

	private int id;
	private int quesId;
	private int parentId;
	private String user;
	private Date createTime;
	private String brief;
	private int type;

	private List<Answer> answers;

	public String getBrief() {
		return brief;
	}

	public void setBrief(String brief) {
		this.brief = brief;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getQuesId() {
		return quesId;
	}

	public void setQuesId(int quesId) {
		this.quesId = quesId;
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}

	public List<Answer> getAnswers() {
		return answers;
	}

	public void setAnswers(List<Answer> answers) {
		this.answers = answers;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public boolean isTop() {
		return this.parentId <= 0;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public boolean isFromQues() {
		return this.type == FROM_QUEST;
	}

	public boolean isFromDB() {
		return this.type == FROM_DB;
	}

	public boolean isIncluded(Subject subject) {
		if (this.isFromQues())
			return subject.isInques();
		return subject.isIndb();
	}
}
